<template>
    <!--布置作业-->
    <div class="exam" v-if="tclassDetail">
        <!--过滤栏-->
        <div class="filter-container">
            <div class="filter-item item-input">
                <el-input v-model="tclassInput" placeholder="请输入教学班名称"></el-input>
            </div>
            <div class="filter-item item-button">
                <el-button type="primary" @click="searchTClassByName()"><i class="el-icon-search"></i> 搜索</el-button>
            </div>
            <div class="filter-item item-button">
                <el-button type="primary" @click="requestTclass(), tclassInput = ''"><i class="el-icon-refresh"></i> 刷新
                </el-button>
            </div>
            <!--<div class="filter-item item-button">-->
            <!--<el-button type="primary" @click="toCreateTClass = true,clearForm(),requestAllNclass()"><i class="el-icon-s-flag"></i> 组建教学班</el-button>-->
            <!--</div>-->
        </div>

        <!--教学班列表-->
        <div class="exam-list">
            <el-table
                    :data="tclassDetail.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                    border
                    style="width: 100%;">
                <el-table-column
                        label="序号"
                        width="60"
                        align="center">
                    <template #default="scope">
                        {{scope.$index + 1}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="教学班名称"
                        width="280"
                        align="center">
                    <template #default="scope">
                        <el-tooltip content="点击查看已布置的作业" placement="top">
                            <span class="col2-cell-style"
                                  @click="viewHomeworkByClass((currentPage - 1) * pageSize + scope.$index)">{{scope.row.name}}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="startTime"
                        label="创建时间" a
                        width="200"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="endTime"
                        label="结束时间"
                        width="200"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="teacher"
                        label="任课老师"
                        width="150"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="status"
                        label="状态"
                        align="center">
                    <template #default="scope">
                        <el-tag type="success" v-if="scope.row.status === 0" disable-transitions>正常</el-tag>
                        <el-tag type="danger" v-else-if="scope.row.status === 1" disable-transitions>异常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="360">
                    <template #default="scope">
                        <!--<el-button-->
                        <!--size="mini"-->
                        <!--type="primary"-->
                        <!--@click="changeTclass((currentPage - 1) * pageSize + scope.$index)">增加、删除班级-->
                        <!--</el-button>-->
                        <el-button
                                size="mini"
                                type="primary"
                                @click="assignHomework((currentPage - 1) * pageSize + scope.$index)">布置作业
                        </el-button>
                        <el-button
                                size="mini"
                                type="success"
                                @click="downloadExcel((currentPage - 1) * pageSize + scope.$index)">下载成绩
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!--分页-->
        <Pagination :currentPage="currentPage" :pageSize="pageSize" :total="tclassDetail.length"
                    :handleSizeChange="handleSizeChange" :handleCurrentChange="handleCurrentChange"></Pagination>

        <!--组建教学班 对话框-->
        <el-dialog title="组建教学班" width="70%" v-model="toCreateTClass">
            <el-form ref="tclassForm" :model="tclassForm" status-icon :rules="tclassRules">
                <el-form-item label="教学班名称" :label-width="formLabelWidth" prop="name">
                    <el-input v-model="tclassForm.name" autocomplete="off" placeholder="请输入班级名称"
                              style="width: 80%"></el-input>
                </el-form-item>
                <el-form-item label="请选择自然班级" prop="nclass" class="transfeTitle">
                </el-form-item>
                <div class="transfeLayout">
                    <el-transfer
                            filterable
                            filter-placeholder="请输入自然班名称"
                            v-model="tclassForm.nclass"
                            :data="nclassData"
                            :titles="transferTitles"
                            :button-texts="transferButtonText">
                    </el-transfer>
                </div>

                <el-form-item label="结课时间" :label-width="formLabelWidth" prop="endTime">
                    <el-date-picker
                            v-model="tclassForm.endTime"
                            type="date"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="timestamp"
                            placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="创建人" :label-width="formLabelWidth" prop="teacher">
                    <el-input v-model="tclassForm.teacher" autocomplete="off" :disabled="true"
                              style="width: 80%;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toCreateTClass = false, clearForm()">取 消</el-button>
                <el-button type="primary" @click="createTClass()">保 存</el-button>
            </div>
        </el-dialog>


        <!--查看该教学班有哪些作业  对话框-->
        <el-dialog title="查看已布置作业" :visible.sync="toViewHomeworkByClass" width="80%" top="2vh">
            <el-table :data="tclassHomeworkDetail"
                      @selection-change="handleSelectionChange"
                      ref="multipleTable">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column property="id" label="题目id" width="100" align="center"></el-table-column>
                <el-table-column property="name" label="题目名称" width="220">
                    <template slot-scope="scope">
                        <el-tooltip content="查看该作业所有学生的提交情况" placement="top">
                            <span class="col2-cell-style"
                                  @click="viewStudentByHomework(scope.$index), eidInput = ''">{{scope.row.name}}</span>
                        </el-tooltip>

                    </template>
                </el-table-column>
                <el-table-column property="startTime" label="开始时间" width="220" align="center"></el-table-column>
                <el-table-column property="endTime" label="结束时间" width="200" align="center"></el-table-column>
                <el-table-column
                        prop="status"
                        label="状态"
                        align="center">
                    <template slot-scope="scope">
                        <el-tag type="success" disable-transitions v-if="scope.row.status == 0">正常</el-tag>
                        <el-tag type="danger" disabel_transitions v-if="scope.row.status == 1">结束</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="400">
                    <template slot-scope="scope">
                        <el-tooltip content="修改作业期限" placement="top">
                            <el-button
                                    size="mini"
                                    type="primary"
                                    @click="changeHomeworkTime(scope.$index)">修改
                            </el-button>
                        </el-tooltip>
                        <el-button
                                size="mini"
                                type="warning"
                                v-if="scope.row.status != 1"
                                @click="toEndHomework = true, curHomeworkIndex = scope.$index">结束
                        </el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                v-if="scope.row.status != 1"
                                @click="toDeleteHomework = true, curHomeworkIndex = scope.$index">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="toViewCloneHomeworkPage = true">克隆作业</el-button>
                <el-button type="primary" @click="downloadExcelBySelectedProblemId()">下载指定题目的学生成绩</el-button>
                <el-button @click="toViewHomeworkByClass = false">取 消</el-button>
            </div>
        </el-dialog>


        <!--修改教学班内自然班  对话框-->
        <el-dialog title="修改教学班信息" width="70%" top="2vh" :visible.sync="toChangeTclass">
            <el-form ref="tclassForm" :model="tclassForm" status-icon :rules="tclassRules">
                <el-form-item label="教学班名称" :label-width="formLabelWidth" prop="name">
                    <el-input v-model="tclassForm.name" autocomplete="off" placeholder="请输入班级名称" style="width: 80%"
                              :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="请选择自然班级" prop="nclass" class="transfeTitle">
                </el-form-item>
                <div class="transfeLayout">
                    <el-transfer
                            filterable
                            filter-placeholder="请输入自然班名称"
                            @change="handleChange"
                            v-model="tclassForm.nclass"
                            :data="nclassData"
                            :titles="transferTitles"
                            :button-texts="transferButtonText">
                    </el-transfer>
                </div>

                <el-form-item label="结课时间" :label-width="formLabelWidth" prop="endTime">
                    <el-date-picker
                            v-model="tclassForm.endTime"
                            type="date"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="timestamp"
                            placeholder="选择日期"
                            :disabled="true">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="创建人" :label-width="formLabelWidth" prop="teacher">
                    <el-input v-model="tclassForm.teacher" autocomplete="off" :disabled="true"
                              style="width: 80%;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toChangeTclass = false, clearForm()">取 消</el-button>
                <el-button type="primary" @click="changeTClassComfirm(curClassIndex)">保 存</el-button>
            </div>
        </el-dialog>


        <!--布置作业-->
        <el-dialog title="添加题目" :visible.sync="toAddQuestion" top="1vh" width="80%">
            <div slot="title" class="header-title">
                <span>选择题目</span>
            </div>

            <!--添加题目 过滤栏-->
            <div class="filter-bar">
                <el-select v-model="categValue" placeholder="请选择题目类型" class="filter-item" clearable filterable
                           @change="problemTypeSearch">
                    <el-option
                            v-for="item in categOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.label"
                    >
                    </el-option>
                </el-select>
                <el-input
                        placeholder="请输入关键词"
                        v-model="questKeyInput"
                        clearable
                        class="filter-item"
                        style="margin-left: 10px;">
                </el-input>
                <el-button type="primary" class="filter-item" @click="searchProblemsByKey">
                    <i class="el-icon-search"></i> 搜索
                </el-button>
                <el-button type="primary" class="filter-item" @click="refreshQuestLib"><i class="el-icon-refresh"></i>
                    刷新
                </el-button>
            </div>

            <!--题目表格-->
            <el-table
                    :data="Lib.slice((questCurPage - 1) * questPageSize, questCurPage * questPageSize)"
                    style="width: 100%"
                    id="problem-table"
                    @expand-change="expandSelect">
                <el-table-column type="expand">
                    <template slot-scope="scope">
                        <div label-position="left" inline class="question-table-expand">
                            <h4>【题目描述】</h4>
                            <p v-html="scope.row.detail.description"></p>
                            <h4>【输入格式】</h4>
                            <p v-html="scope.row.detail.input"></p>
                            <h4>【输出格式】</h4>
                            <p v-html="scope.row.detail.output"></p>
                            <h4>【输入样例】</h4>
                            <p v-html="scope.row.detail.inputSample"></p>
                            <h4>【输出样例】</h4>
                            <p v-html="scope.row.detail.outputSample"></p>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                        label="#"
                        width="80"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.$index + 1}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="题目"
                        prop="name"
                        width="250">
                </el-table-column>
                <el-table-column
                        label="类型"
                        prop="type"
                        align="center"
                        width="250">
                </el-table-column>
                <el-table-column
                        label="难度"
                        prop="difficulty"
                        align="center"
                        width="200">
                </el-table-column>
                <el-table-column
                        label="来源"
                        prop="source"
                        align="center">
                </el-table-column>
                <el-table-column label="操作" width="250">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                type="success"
                                @click="addQuestion((questCurPage - 1) * questPageSize + scope.$index)">发布
                        </el-button>
                        <el-button
                                size="mini"
                                type="warning"
                                @click="viewProblemDetail((questCurPage - 1) * questPageSize + scope.$index)">查看详情
                        </el-button>
                        <!--                        <el-button-->
                        <!--                                size="mini"-->
                        <!--                                type="danger"-->
                        <!--                                v-if="Lib[(questCurPage - 1) * questPageSize + scope.$index].isAdded == true">删除-->
                        <!--                        </el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <Pagination :currentPage="questCurPage" :pageSize="questPageSize"
                        :total="Lib.length" :handleSizeChange="handleSizeChange3"
                        :handleCurrentChange="handleCurrentChange3"></Pagination>
        </el-dialog>

        <!--        创建作业对话框-->
        <el-dialog title="布置作业" :visible.sync="toCreateHomework">
            <el-form ref="homeworkForm" :model="homeworkForm" status-icon :rules="homeworkRules">
                <el-form-item label="作业名称" :label-width="formLabelWidth" prop="name" style="width: 90%">
                    <span>&nbsp;{{ homeworkForm.name }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
                <el-form-item label="班级名称" :label-width="formLabelWidth" prop="tclass">
                    <span>&nbsp;{{ homeworkForm.tclass }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
                <el-form-item label="起止时间" :label-width="formLabelWidth" prop="dateTime">
                    <!--<el-date-picker-->
                    <!--v-model="homeworkForm.dateTime"-->
                    <!--type="datetime"-->
                    <!--placeholder="请选择结束时间">-->
                    <!--</el-date-picker>-->
                    <el-date-picker
                            v-model="homeworkForm.dateTime"
                            type="datetimerange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="选择语言" :label-width="formLabelWidth" style="width: 90%">
                    <div class="filter-bar">
                        <el-select v-model="language" placeholder="语言" class="filter-item">
                            <el-option
                                    v-for="item in languages"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </el-form-item>

                <el-form-item label="创建人" :label-width="formLabelWidth" prop="teacher" style="width: 90%">
                    <span>&nbsp;{{ homeworkForm.teacher }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toCreateHomework = false, clearForm()">取 消</el-button>
                <el-button type="primary" @click="createHomework()">创 建</el-button>
            </div>
        </el-dialog>

        <el-dialog title="克隆作业" :visible.sync="toViewCloneHomeworkPage">
            <el-row>
                <el-col :span="8">
                    <el-select v-model="cloneClassId" placeholder="克隆前的作业班级名称" class="filter-item" clearable filterable
                               @change="searchCloneHomeworkProblem">
                        <el-option
                                v-for="item in allTClasses"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-col>
                <el-col :span="8">
                    <el-input v-model="addCloneDays" placeholder="克隆作业增加的天数">
                    </el-input>
                </el-col>

                <el-col :span="2">
                    <el-button @click="modifyCloneHomeworkTime()" type="success">
                        原作业时间顺延天数
                    </el-button>
                </el-col>
            </el-row>

            <el-table :data="cloneSourceProblem"
                      @selection-change="handleSelectCloneProblem"
                      ref="multipleTable">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column property="id" label="题目id" width="100" align="center"></el-table-column>
                <el-table-column property="name" label="题目名称" width="220"></el-table-column>
                <el-table-column property="language" label="语言" width="60"></el-table-column>
                <el-table-column property="startTime" label="开始时间" width="220" align="center"></el-table-column>
                <el-table-column property="endTime" label="结束时间" width="200" align="center"></el-table-column>
            </el-table>
            <br>
            <br>
            <el-row>
                <el-col :span="8">
                    <el-input v-model="cloneHomeworkForm.teacher" :disabled="true">
                    </el-input>
                </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="cloneHomework()">克 隆</el-button>
                <el-button @click="toViewCloneHomeworkPage = false">取 消</el-button>
            </div>
        </el-dialog>

        <!--查看题目详情 对话框-->
        <el-dialog title="查看题目详情" :visible.sync="toViewProblemDetail" top="2vh" width="60%">
            <div slot="title" class="header-title">
                <span></span>
            </div>

            <!--题目详情-->
            <el-row :gutter="20">
                <el-col :span="17">
                    <div class="problem-detail">
                        <div class="problem-header">
                            <span class="problem-name">查看题目详情：{{problemDetail.name}}</span>
                        </div>
                        <div class="problem-body">
                            <section>
                                <h4>描述</h4>
                                <div class="description">
                                    <p v-html="problemDetail.detail.description"></p>
                                </div>
                            </section>
                            <section class="border-top-style">
                                <h4>格式</h4>
                                <h5>输入格式</h5>
                                <div class="description">
                                    <p v-html="problemDetail.detail.input"></p>
                                </div>
                                <h5>输出格式</h5>
                                <div class="description">
                                    <p v-html="problemDetail.detail.output"></p>
                                </div>
                            </section>
                            <section class="border-top-style sample">
                                <h4>样例</h4>
                                <h5>输入样例</h5>
                                <div class="description">
                                    <pre v-html="problemDetail.detail.inputSample"></pre>
                                </div>
                                <h5>输出样例</h5>
                                <div class="description">
                                    <pre v-html="problemDetail.detail.outputSample"></pre>
                                </div>
                            </section>
                            <section class="border-top-style">
                                <h4>限制</h4>
                                <div class="description">
                                    <p><strong>时间限制：</strong>{{problemDetail.detail.timeLimit}} ms</p>
                                    <p><strong>内存限制：</strong>{{problemDetail.detail.memoryLimit}} KB</p>
                                </div>
                            </section>
                            <section class="border-top-style"
                                     v-if="problemDetail.detail.hint != null && problemDetail.detail.hint.trim().length !== 0">
                                <h4>提示</h4>
                                <div class="description">
                                    <p v-html="problemDetail.detail.hint"></p>
                                </div>
                            </section>
                            <section class="border-top-style">
                                <h4>测试集</h4>
                                <div class="description">
                                    <div class="sample checkpoints" v-for="(item, index) in curCheckpoints"
                                         :class="index == 0 ? 'first-checkpoint' : ''">
                                        <h5>测试点 {{index + 1}}</h5>
                                        <h6>输入</h6>
                                        <pre>{{item.checkpoint_input}}</pre>
                                        <h6>输出</h6>
                                        <pre>{{item.checkpoint_output}}</pre>
                                    </div>
                                </div>
                            </section>
                            <section class="border-top-style">
                                <h4>{{standardAnswerLanguage}} 标准答案</h4>
                                <div class="description">
                                    <div class="sample checkpoints">
                                        <pre>{{standardAnswer}}</pre>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </el-col>

                <el-col :span="7">
                    <div class="p-operation">
                        <h4>试题操作</h4>
                        <div class="op-list">
                            <ul>
                                <li class="op-li" @click="judgeSubmit">提交代码</li>
                                <li class="li-score">得分：{{score}}</li>
                                <li class="li-score">结果：<span :style="resultColor">{{judgeResult}}</span></li>
                            </ul>
                        </div>
                    </div>
                </el-col>
            </el-row>



            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="toViewProblemDetail = false">关闭</el-button>
            </div>
        </el-dialog>

        <el-dialog title="查看作业详情" :visible.sync="toViewHomeworkDetail" fullscreen>
            <div slot="title" class="header-title">
                <span>{{ homeworkTitle }}</span>
            </div>

            <!--过滤栏-->
            <div class="filter-bar">
                <el-input
                        placeholder="请输入学号搜索"
                        v-model="eidInput"
                        clearable
                        class="filter-item">
                </el-input>
                <el-button type="primary" class="filter-item" @click="searchStudentsById">
                    <i class="el-icon-search "></i> 搜索
                </el-button>
                <el-button type="primary" class="filter-item item-margin-left-16"
                           @click="viewStudentByHomework(curHomeworkIndex), eidInput = ''">
                    <i class="el-icon-refresh"></i> 刷新
                </el-button>
                <el-tooltip content="下载本次作业的重复率检测报告" placement="top">
                    <el-button type="primary" class="filter-item item-margin-left-16" @click="downloadRepCheckReport">
                        <i class="el-icon-s-opportunity"></i> 查重报告
                    </el-button>
                </el-tooltip>
                <el-button type="primary" class="filter-item item-margin-left-16" @click="toViewHomeworkDetail = false">
                    <i class="el-icon-circle-close"></i> 关闭页面
                </el-button>
            </div>

            <!--学生表格-->
            <el-table
                    :data="studentDetail.slice((stuCurPage - 1) * stuPageSize, stuCurPage * stuPageSize)"
                    border
                    style="width: 100%"
                    id="exportTable">
                <el-table-column
                        label="序号"
                        width="80"
                        align="center">
                    <template slot-scope="scope">
                        {{scope.$index + 1}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="学号"
                        prop="id"
                        width="200"
                        align="center">
                </el-table-column>
                <el-table-column
                        label="姓名"
                        prop="name"
                        width="200"
                        align="center">
                    <template slot-scope="scope">
                        <el-tooltip content="查看学生答案和修改分数" placement="top">
                            <span class="col2-cell-style"
                                  @click="reviewStuPaper((stuCurPage - 1) * stuPageSize + scope.$index)">{{scope.row.name}}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column
                        label="成绩"
                        prop="grade"
                        width="150"
                        align="center">
                </el-table-column>
                <el-table-column
                        label="提交次数"
                        prop="submitCount"
                        align="center">
                </el-table-column>
                <el-table-column
                        label="提交时间"
                        prop="submitTime"
                        width="250"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="status"
                        label="状态"
                        width="150"
                        align="center">
                    <template slot-scope="scope">
                        <el-tooltip content="学生未提交作业" placement="top">
                            <el-tag v-if="scope.row.submitCount == 0" disable-transitions>未提交</el-tag>
                        </el-tooltip>
                        <el-tooltip content="学生已提交作业" placement="top">
                            <el-tag v-if="scope.row.submitCount > 0" type="success" disable-transitions>已提交</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="400">
                    <template slot-scope="scope">
                        <!--                        <el-button-->
                        <!--                                size="mini"-->
                        <!--                                type="danger"-->
                        <!--                                v-if="examDetail[curExamIndex].status <= 1 "-->
                        <!--                                @click="deleteExaminee((stuCurPage - 1) * stuPageSize + scope.$index)">删除-->
                        <!--                        </el-button>-->
                        <el-button
                                size="mini"
                                type="info"
                                v-if="scope.row.status == 3">重新阅卷
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!--分页-->
            <Pagination :currentPage="stuCurPage" :pageSize="stuPageSize"
                        :total="studentDetail.length" :handleSizeChange="handleSizeChange2"
                        :handleCurrentChange="handleCurrentChange2"></Pagination>

        </el-dialog>

        <!--查阅试卷 对话框-->
        <el-dialog title="" :visible.sync="toReviewStuPaper" top="2vh" width="80%" v-if="toReviewStuPaper">
            <div class="stu-paper-container">
                <div class="stu-paper-header">
                    <h1>{{ homeworkTitle }}</h1>
                    <el-row :gutter="20">
                        <el-col :span="6">
                            <h3>学号：{{studentDetail[curStuIndex].id}}</h3>
                        </el-col>
                        <el-col :span="6">
                            <h3>姓名：{{studentDetail[curStuIndex].name}}</h3>
                        </el-col>
                        <el-col :span="6">
                            <h3>提交次数：{{studentDetail[curStuIndex].submitCount}}</h3>
                        </el-col>
                        <el-col :span="6">
                            <h3>得分：{{studentDetail[curStuIndex].grade}}</h3>
                        </el-col>
                    </el-row>
                </div>
                <div class="stu-paper-content">
                    <h2>第 1 题
                        <el-input-number style="float: right" size="mini" v-model="studentDetail[curStuIndex].grade"
                                         :min="0"
                                         :max="100" label="分数"
                                         :disabled="studentDetail[curStuIndex].answer == null || studentDetail[curStuIndex].submitCount == 0"></el-input-number>
                    </h2>
                    <h4 style="clear: both">【题目描述】</h4>
                    <pre style="white-space: pre-wrap"
                         v-html="tclassHomeworkDetail[curHomeworkIndex].description"></pre>
                    <h4>【学生答案】</h4>
                    <div class="stu-answer" v-highlight>
                        <pre>
                            <code :class="studentDetail[curStuIndex].language">{{studentDetail[curStuIndex].answer}}</code>
                        </pre>
                        <!--<div :class="studentDetail[curStuIndex].language" v-html="studentDetail[curStuIndex].answer"></div>-->
                    </div>
                </div>
                <div class="stu-paper-footer">
                    <el-button v-if="studentDetail[curStuIndex].submitCount > 0"
                               @click="toReviewStuPaper = false">取 消
                    </el-button>
                    <el-button v-if="studentDetail[curStuIndex].submitCount > 0"
                               type="primary" @click="uploadScore">提交分数
                    </el-button>
                </div>
            </div>
        </el-dialog>


        <!--修改作业期限 对话框-->
        <el-dialog title="修改作业期限" :visible.sync="toChangeHomeworkTime">
            <el-form ref="homeworkForm" :model="homeworkForm" status-icon :rules="homeworkRules">
                <el-form-item label="作业名称" :label-width="formLabelWidth" prop="name" style="width: 90%">
                    <span>&nbsp;{{ homeworkForm.name }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
                <el-form-item label="班级" :label-width="formLabelWidth" prop="tclass">
                    <span>&nbsp;{{ homeworkForm.tclass }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
                <el-form-item label="起止时间" :label-width="formLabelWidth" prop="dateTime">
                    <!--<el-date-picker-->
                    <!--v-model="homeworkForm.dateTime"-->
                    <!--type="datetime">-->
                    <!--</el-date-picker>-->
                    <el-date-picker
                            v-model="homeworkForm.dateTime"
                            type="datetimerange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="选择语言" :label-width="formLabelWidth" style="width: 90%">
                    <div class="filter-bar">
                        <el-select v-model="language" placeholder="语言" class="filter-item">
                            <el-option
                                    v-for="item in languages"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </el-form-item>

                <el-form-item label="创建人" :label-width="formLabelWidth" prop="teacher" style="width: 90%">
                    <span>&nbsp;{{ homeworkForm.teacher }}&nbsp;&nbsp;&nbsp;</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toChangeHomeworkTime = false, clearForm()">取 消</el-button>
                <el-button type="primary" @click="changeHomeworkTimeComfirm()">修 改</el-button>
            </div>
        </el-dialog>


        <!--结束作业 对话框-->
        <el-dialog title="" :visible.sync="toEndHomework" top="18vh" width="33%" center :show-close="false">
            <div class="take-up-header">
                <div class="header-icon">
                    <span class="icon-text">!</span>
                </div>
            </div>
            <div class="take-up-content">是否提前结束本次作业？结束之后学生将无法提交作业</div>
            <div slot="footer">
                <el-button type="primary" @click="endHomework(curHomeworkIndex)">确定结束</el-button>
                <el-button type="info" @click="toEndHomework = false">取消</el-button>
            </div>
        </el-dialog>

        <!--删除作业 对话框-->
        <el-dialog title="" :visible.sync="toDeleteHomework" top="18vh" width="33%" center :show-close="false">
            <div class="take-up-header">
                <div class="header-icon">
                    <span class="icon-text">!</span>
                </div>
            </div>
            <div class="take-up-content">是否删除本次作业？删除之后学生将无法提交作业，如果已有学生提交则无法删除</div>
            <div slot="footer">
                <el-button type="primary" @click="deleteHomework(curHomeworkIndex)">确定删除</el-button>
                <el-button type="info" @click="toDeleteHomework = false">取消</el-button>
            </div>
        </el-dialog>

        <!--提交代码，对话框-->
        <el-dialog title="提交代码" :visible.sync="toSubmitCode" top="2vh" width="46%">
            <div slot="title" class="header-title">
                <span>提交代码：{{problemDetail.name}}</span>
            </div>

            <div class="filter-bar">
                <el-select v-model="language" placeholder="语言" class="filter-item" @change="setHighlight()">
                    <el-option
                            v-for="item in languages"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </div>

            <div class="code-area" contenteditable="true">
                <codemirror
                        v-model="code"
                        :options="cmOptions"
                        class="code">
                </codemirror>
            </div>

            <div slot="footer" class="dialog-footer">
                <el-button @click="toSubmitCode = false">取 消</el-button>
                <el-button type="primary" @click="submitCode()">提 交</el-button>
            </div>
        </el-dialog>


        <!--查看提交记录，对话框-->
<!--        <el-dialog title="查看提交记录" :visible.sync="toViewSubRecord" top="2vh" width="56%">-->
<!--            <div slot="title" class="header-title">-->
<!--                <span></span>-->
<!--            </div>-->

<!--            <div class="sub-record">-->
<!--                <div class="rec-header">-->
<!--                    <span class="problem-name">查看提交记录：{{problemDetail.name}}</span>-->
<!--                </div>-->
<!--                <div class="rec-body">-->
<!--                    <section>-->
<!--                        <h4>概况</h4>-->
<!--                        <div class="sketch">-->
<!--                            <el-row :gutter="20">-->
<!--                                <el-col :span="8" class="item">语言</el-col>-->
<!--                                <el-col :span="16">{{record.language}}</el-col>-->
<!--                            </el-row>-->
<!--                            <el-row :gutter="20">-->
<!--                                <el-col :span="8" class="item">提交时间</el-col>-->
<!--                                <el-col :span="16">{{record.submitTime}}</el-col>-->
<!--                            </el-row>-->
<!--                            <el-row :gutter="20">-->
<!--                                <el-col :span="8" class="item">得分</el-col>-->
<!--                                <el-col :span="16">{{record.judgeScore}}</el-col>-->
<!--                            </el-row>-->
<!--                            <el-row :gutter="20">-->
<!--                                <el-col :span="8" class="item">结果</el-col>-->
<!--                                <el-col :span="16" :style="resultColor">{{record.judge_result}}</el-col>-->
<!--                            </el-row>-->
<!--                        </div>-->
<!--                    </section>-->
<!--                    <section class="border-top-style">-->
<!--                        <h4>代码</h4>-->
<!--                        <div class="answer-result" v-highlight>-->
<!--                            <pre>-->
<!--                                <code ref="codeText" :class="record.language">{{record.answer}}</code>-->
<!--                            </pre>-->
<!--                        </div>-->
<!--                    </section>-->
<!--                    <section class="border-top-style">-->
<!--                        <h4>评测详情</h4>-->
<!--                        <div class="answer-result" v-html="record.judge_log"></div>-->
<!--                    </section>-->
<!--                </div>-->
<!--            </div>-->

<!--            <div slot="footer" class="dialog-footer">-->
<!--                <el-button type="primary" @click="toViewSubRecord = false">关闭</el-button>-->
<!--            </div>-->
<!--        </el-dialog>-->

    </div>
</template>

<script>
    import Pagination from './Pagination';
    import Axios from 'axios';
    import FileSaver from 'file-saver';
    import XLSX from 'xlsx';
    import qs from 'qs';

    import {codemirror} from 'vue-codemirror';
    import hljs from 'highlight.js';

    //导入使用的语言语法定义文件
    //导入使用的语言语法定义文件
    require("codemirror/mode/python/python.js");
    require("codemirror/mode/javascript/javascript.js");
    require("codemirror/mode/clike/clike.js");
    require("codemirror/mode/shell/shell.js");
    //导入选中的theme文件
    require("codemirror/theme/idea.css");
    //导入自动提示核心文件及样式
    require("codemirror/addon/hint/show-hint.css");
    require("codemirror/addon/hint/show-hint.js");
    //导入指定语言的提示文件
    require("codemirror/addon/hint/javascript-hint.js");

    export default {
        name: "",
        data: function () {
            return {
                toSubmitCode: false,
                code: '',
                score: '',//得分
                judgeResult: '',//评测结果
                resultColor: {},//结果颜色
                record: {},
                toViewSubRecord: false,
                currentSubmissionId: 0,
                problemDetail: {
                    id: '',
                    name: '',
                    type: '',
                    stem: '',
                    source: '',
                    difficulty: '',
                    isAdded: false,
                    detail: {
                        description: '',
                        input: '',
                        output: '',
                        inputSample: '',
                        outputSample: '',
                    }
                },
                standardAnswer: '管理员尚未发布标准答案...',
                standardAnswerLanguage: '',
                currentClassId: -1,
                questCurPage: 1, // 题库当前页码
                questPageSize: 20, // 题库每页条目个数
                stuCurPage: 1,  //学生
                stuPageSize: 20,
                questKeyInput: '',
                tclassInput: '',
                toAddQuestion: false,
                toCreateHomework: false,
                toViewProblemDetail: false,
                toReviewStuPaper: false,
                toViewHomeworkByClass: false,
                toViewCloneHomeworkPage: false,
                toDeleteHomework: false,
                toViewHomeworkDetail: false,
                toChangeHomeworkTime: false,
                toEndHomework: false,
                toDeleteTClass: false, //是否删除教学班对话框
                toCreateTClass: false, //是否创建教学班对话框
                toViewTclassDetail: false, //查看教学班对话框
                toChangeTclass: false, //增删教学班内自然班对话框
                tclassDetail: [],     //教学班列表
                allTClasses: [],    //所有教学班级
                currentPage: 1,
                pageSize: 20,
                curClassIndex: 0,//查看教学班的班级序号
                curStuIndex: 0,//查看学生的学生序号
                curHomeworkIndex: 0,//查看作业的作业序号
                curProblemIndex: 0,//创建作业的题目序号
                tclassForm: {
                    name: '',
                    nclass: [],
                    endTime: '',
                    teacher: localStorage.getItem("teacherName"), //在点击组建教学班时，自动将老师名字填入表格中，且无法修改。
                },
                transferTitles: ['未选择', '已选择'], //组建班级对话框中穿梭框的标题
                transferButtonText: ['删除', '添加'], //组建班级对话框中穿梭框的两个按钮
                tclassHomeworkDetail: [],
                formLabelWidth: '120px',
                tclassRules: {
                    name: [
                        {required: true, message: '请输入教学班名称', trigger: 'blur'},
                        {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
                    ],
                    nclass: [
                        {required: true, message: '请选择班级', trigger: 'blur'}
                    ],
                    endTime: [
                        {required: true, message: '请选择结束教学日期', trigger: 'blur'}
                    ],
                },
                nclassData: [],
                categValue: '', //试题类型搜索框
                homeworkTitle: '',
                eidInput: '',
                categOptions: [{
                    value: '选项0',
                    label: '图论',
                }, {
                    value: '选项1',
                    label: '动态规划',
                }, {
                    value: '选项2',
                    label: '基础编程',
                }],
                homeworkForm: {
                    name: '',
                    tclass: '',
                    dateTime: '',
                    teacher: localStorage.getItem("teacherName"),
                },
                cloneHomeworkForm: {
                    homeworkName: '',
                    tclass: '',
                    dateTime: '',
                    teacher: localStorage.getItem("teacherName"),
                },
                addCloneDays: '',
                cloneClassId: '',
                cloneSourceProblem: [],
                oldCloneSourceProblem: [],

                qLib: [], //题库
                Lib: [{    //显示的题库
                    id: 1,
                    name: 'A + B Problem',
                    type: '基础编程',
                    stem: '简单描述',
                    source: '本校题库',
                    difficulty: 'easy',
                    isAdded: false,
                    detail: {
                        description: '题目描述',
                        input: 'input',
                        output: 'output',
                        inputSample: 'inputSample',
                        outputSample: 'outputSample',
                    }
                }, {
                    id: 2,
                    name: 'A + B Problem 1',
                    type: '基础编程1',
                    stem: '简单描述1',
                    source: '本校题库',
                    difficulty: 'medium',
                    isAdded: false,
                    detail: {
                        description: '题目描述',
                        input: 'input',
                        output: 'output',
                        inputSample: 'inputSample',
                        outputSample: 'outputSample',
                    }
                }],
                homeworkRules: {
                    dateTime: [
                        {required: true, message: '请选择日期', trigger: 'blur'}
                    ],
                },
                curCheckpoints: [], //当前题目测试集
                studentDetail: [],
                hwStudents: [],  //某个作业的所有学生及其提交情况
                languageSelect: 0,
                evaluationSelect: 0,
                language: 'C',
                languages: [{
                    value: 'C'
                }, {
                    value: 'C++'
                }, {
                    value: 'Java'
                }, {
                    value: 'Python3'
                }
                ],

                cmOptions: {
                    theme: "idea",
                    mode: "text/x-csrc",   //识别的语言 c
                    // mode: "text/x-c++src",  //识别的语言 c++
                    // mode: "text/x-java",  //识别的语言 java
                    // mode: "text/javascript", //识别的语言 javascript
                    lineNumbers: true,   //显示行号
                    line: true,
                    indentUnit: 4,
                    // lineWrapping: true  //代码折叠
                },

                selectedProblemList: [],
                cloneSelectProblemList: [],

            }
        },
        components: {
            Pagination,
            codemirror
        },
        mounted() {
            if (localStorage.getItem("teacherToken") != null && localStorage.getItem("loginStatus") == 'teacher') {
                this.requestTclass();
                this.requestAllNclass();
                this.requestLib();
                this.requestProblemType();
            } else {
                this.$router.push({path: "/login"})
            }
        },
        methods: {

            judgeSubmit() {
                this.toSubmitCode = true;
            },

            //提交代码时根据 设置的语言 设置 代码的高亮
            setHighlight() {
                if (this.language == 'C') this.cmOptions.mode = "text/x-csrc";
                else if (this.language == 'C++') this.cmOptions.mode = "text/x-c++src";
                else if (this.language == 'Java') this.cmOptions.mode = "text/x-java";
            },

            //提交代码
            submitCode() {
                if (this.code.length != 0) {
                    let that = this;
                    this.$axios({
                        method: 'post',
                        url: '/teacher/testHomeWork',
                        data: {
                            problemId: this.problemDetail.id,
                            answer: this.code,
                            languageName: this.language,
                            teacherToken: localStorage.getItem("teacherToken"),
                        },
                        transformRequest: [
                            function (data) {
                                let ret = '';
                                for (let it in data) {
                                    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                                }
                                ret = ret.substring(0, ret.lastIndexOf('&'));
                                return ret;
                            }
                        ],
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        },
                    }).then((res) => {
                        if (res.data == 3) {
                            this.$router.push({path: "/login"})
                            return;
                        }
                        // console.log(res.data)
                        if (res.data.content.isSuccessful) {
                            this.$notify({
                                title: '成功',
                                message: '提交成功，正在评分，请您稍等片刻！',
                                type: 'success',
                                duration: 3000
                            });
                            this.code = '';
                            this.toSubmitCode = false;
                            this.currentSubmissionId = res.data.content.submissionId;
                            let updateScore = setTimeout(that.waitResult, 5000);
                        }
                    }).catch((err) => {
                        this.subIsDisabled = false;
                        this.$notify({
                            title: '错误',
                            message: '提交失败',
                            type: 'error',
                            duration: 3000
                        });
                        console.log(err);
                    });
                } else {
                    this.$notify({
                        title: '警告',
                        message: '内容不能为空，请提交代码！',
                        type: 'warning',
                        duration: 3000
                    });
                }

            },

            //等待结果（得分）
            waitResult() {
                this.viewSubRecord();
            },

            //flag：0表示仅获取提交数据 1表示查看提交记录
            viewSubRecord() {
                let that = this;
                if (this.currentSubmissionId == 0) {
                    return;
                }
                this.$axios({
                    method: 'post',
                    url: '/teacher/getCurrentSubmission',
                    data: {
                        submissionId: this.currentSubmissionId,
                        teacherToken: localStorage.getItem("teacherToken"),
                    },
                    transformRequest: [
                        function (data) {
                            let ret = '';
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret;
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    if (res.data.content.judgeLog != null)
                        res.data.content.judgeLog = res.data.content.judgeLog.replace(/\n/g, "<br>");
                    let jResult = res.data.content.judgeResult.judgeResultSlug;
                    this.judgeResult = jResult;
                    this.score = res.data.content.judgeScore;
                    if (jResult == 'AC') {
                        res.data.content.judge_result = 'Accepted';
                        this.resultColor = "color: #49a932";
                    } else if (jResult == 'PD') {
                        res.data.content.judge_result = 'Pending';
                        this.resultColor = "color: #ffa500";
                    } else if (jResult == 'WA') {
                        res.data.content.judge_result = 'Wrong Answer';
                        this.resultColor = "color: #4d7aff";
                    } else if (jResult == 'TLE') {
                        res.data.content.judge_result = 'Time Limit Exceed';
                        this.resultColor = "color: red";
                    } else if (jResult == 'OLE') {
                        res.data.content.judge_result = 'Output Limit Exceed';
                        this.resultColor = "color: red";
                    } else if (jResult == 'MLE') {
                        res.data.content.judge_result = 'Memory Limit Exceed';
                        this.resultColor = "color: red";
                    } else if (jResult == 'RE') {
                        res.data.content.judge_result = 'Runtime Error';
                        this.resultColor = "color: red";
                    } else if (jResult == 'PE') {
                        res.data.content.judge_result = 'Presentation Error';
                        this.resultColor = "color: red";
                    } else if (jResult == 'CE') {
                        res.data.content.judge_result = 'Compile Error';
                        this.resultColor = "color: red";
                    } else if (jResult == 'SE') {
                        res.data.content.judge_result = 'System Error';
                        this.resultColor = "color: red";
                        this.$message.error("评测机内部错误，请联系管理员")
                    }

                }).catch((err) => {
                    this.$notify({
                        title: '错误',
                        message: '数据获取失败！',
                        type: 'error',
                        duration: 3000
                    });
                    console.log(err);
                });
            },

            handleSelectionChange(val) {
                this.selectedProblemList = val;
                console.log(this.selectedProblemList)
            },

            handleSelectCloneProblem(val) {
                this.cloneSelectProblemList = val;
                console.log(this.cloneSelectProblemList)
            },

            expandSelect() {
                this.$nextTick(function () { //这里要注意，使用$nextTick等组件数据渲染完之后再调用MathJax渲染方法，要不然会获取不到数据
                    if (this.commonsVariable.isMathjaxConfig) {//判断是否初始配置，若无则配置。
                        this.commonsVariable.initMathjaxConfig();
                    }
                    this.commonsVariable.MathQueue("problem-table");//传入组件id，让组件被MathJax渲染
                })
            },

            //根据名称搜索教学班级
            searchTClassByName() {
                if (this.tclassInput.length > 0) {
                    let tClassesByName = [];
                    this.currentPage = 1;
                    for (let i = 0; i < this.allTClasses.length; i++) {
                        if (this.allTClasses[i].name.indexOf(this.tclassInput) >= 0) {
                            tClassesByName.push(this.allTClasses[i]);
                        }
                    }
                    this.tclassDetail = tClassesByName;
                } else
                    this.$message.warning("请先输入教学班名称关键词！");
            },
            //根据学号搜索学生
            searchStudentsById() {
                if (this.eidInput.length > 0) {
                    let hwStusById = [];
                    this.stuCurPage = 1;
                    for (let i = 0; i < this.hwStudents.length; i++) {
                        if (this.hwStudents[i].id.indexOf(this.eidInput) >= 0)
                            hwStusById.push(this.hwStudents[i]);
                    }
                    this.studentDetail = hwStusById;
                } else
                    this.$message.warning("请先输入学号！");
            },
            handleSizeChange3(val) {
                this.questPageSize = val;
            },
            handleCurrentChange3(val) {
                this.questCurPage = val;
            },
            handleSizeChange2(val) {
                this.stuPageSize = val;
            },
            handleCurrentChange2(val) {
                this.stuCurPage = val;
            },
            handleSizeChange(val) {
                this.pageSize = val;
            },
            handleCurrentChange(val) {
                this.currentPage = val;
            },
            //询问是否删除教学班对话框
            deleteDialog(index) {
                this.toDeleteTClass = true;
                this.curClassIndex = index;
            },
            //确认删除教学班
            deleteTClass(index) {
                this.tclassDetail.splice(index, 1);
                this.$message('删除成功');
                this.toDeleteTClass = false;
            },
            //创建教学班
            createTClass() {
                let pattern = /[ `!@#$%^&*()_+=\[\]{};':"\\|,.<>\/?~]/;
                if (pattern.test(this.tclassForm.name)) {
                    this.$message.warning('班级名称不能包含特殊字符')
                    return;
                }
                this.$refs['tclassForm'].validate((valid) => {
                    if (valid) {
                        // console.log(this.tclassForm.nclass);
                        // console.log(this.tclassForm.endTime);
                        let startTime = new Date().getTime();
                        let endTime = new Date(this.tclassForm.endTime);

                        if (startTime >= endTime) {
                            this.$message.error("结课时间只能是现在时间之后");
                            return;
                        }

                        let newTClass = {};
                        newTClass.class_id = null;
                        newTClass.class_name = this.tclassForm.name;
                        newTClass.teacher_id = localStorage.getItem("teacherId");
                        newTClass.create_time = startTime;
                        newTClass.end_time = this.tclassForm.endTime;
                        newTClass.status = "0";

                        Axios({
                            method: 'post',
                            url: '/teacher/createTClass',
                            data: {
                                teacherToken: localStorage.getItem("teacherToken"),
                                nClassesId: this.tclassForm.nclass,
                                tClass: newTClass,
                            },
                            // transformRequest: [
                            //     function (data) {
                            //         let ret = ''
                            //         for (let it in data) {
                            //             ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            //         }
                            //         ret = ret.substring(0, ret.lastIndexOf('&'));
                            //         return ret
                            //     }
                            // ],
                            headers: {
                                'Content-Type': 'application/json'
                            },
                        }).then((res) => {
                            if (res.data == 3) {
                                this.$router.push({path: "/login"})
                                return;
                            }
                            if (res.data.state == 0) {
                                this.$message.error(res.data.message);
                                return;
                            }
                            if (res.data.state == 1) {
                                this.$message({
                                    message: '创建教学班级成功',
                                    type: 'success',
                                });
                                this.toCreateTClass = false;
                                this.clearForm();
                                this.requestTclass();
                                return;
                            }
                        }).catch((err) => {
                            console.log(err);
                        })


                    }
                })
            },
            //修改教学班内的自然班
            changeTclass(index) {
                var that = this;
                this.curClassIndex = index;
                this.clearForm();
                let nclass = [];
                this.requestAllNclass();
                Axios({
                    method: 'post',
                    url: '/teacher/findNClassByTClassId',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        classId: this.tclassDetail[index].id,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data) {
                        for (let i = 0; i < res.data.length; i++) {
                            let tempClass = {};
                            nclass.push(res.data[i].classId);
                            tempClass.key = res.data[i].classId;
                            tempClass.label = res.data[i].className;
                            this.nclassData.push(tempClass)
                        }
                    }
                }).catch((err) => {
                    console.log(err);
                });
                // console.log(nclass);

                this.tclassForm.name = this.tclassDetail[index].name,
                    this.tclassForm.nclass = nclass,
                    this.tclassForm.endTime = this.tclassDetail[index].endTimestamp,
                    this.tclassForm.teacher = localStorage.getItem("teacherName"),

                    that.$nextTick(function () {
                        // console.log(2222222);
                        that.toChangeTclass = true;
                    })
            },
            //清除表格
            clearForm() {
                this.tclassForm = {
                    name: '',
                    nclass: [],
                    endTime: '',
                    teacher: localStorage.getItem("teacherName"),
                }
            },
            clearHomeworkForm() {
                this.homeworkForm = {
                    name: '',
                    tclass: '',
                    dateTime: '',
                    teacher: localStorage.getItem("teacherName"),
                }
            },
            //确认修改教学班内信息
            changeTClassComfirm(index) {
                // this.tclassDetail[index].nclass = this.tclassForm.nclass;
                this.requestTclass();
                this.toChangeTclass = false;
            },
            //获取教学班
            requestTclass() {
                Axios({
                    method: 'post',
                    url: '/teacher/findTClassByTeacherId',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        teacherId: localStorage.getItem("teacherId"),
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log(res);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data) {
                        this.currentPage = 1;
                        this.tclassDetail = [];
                        for (let i = 0; i < res.data.length; i++) {
                            let tclass = {};
                            tclass.id = res.data[i].class_id;
                            tclass.name = res.data[i].class_name;
                            tclass.startTimestamp = res.data[i].create_time;
                            tclass.startTime = this.getTime(res.data[i].create_time);
                            tclass.endTimestamp = res.data[i].end_time;
                            tclass.endTime = this.getTime(res.data[i].end_time);
                            tclass.status = res.data[i].status;
                            // ;tclass.nclass = [201900008,201900026]
                            tclass.teacher = localStorage.getItem("teacherName");
                            this.tclassDetail.push(tclass);
                        }
                        this.allTClasses = this.tclassDetail;
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            //获取教学班的自然班(template)
            requestNclass(tclass) {
                Axios({
                    method: 'post',
                    url: '/teacher/findNClassByTClassId',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        classId: tclass,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data) {
                        this.tclassData = [];
                        for (let i = 0; i < res.data.length; i++) {
                            let nclass = {};
                            nclass.id = res.data[i].classId;
                            nclass.name = res.data[i].className;
                            nclass.acadimicName = res.data[i].academy_name;
                            this.tclassData.push(nclass);
                        }
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            //获取未被其他教学班选取的自然班
            requestAllNclass() {
                Axios({
                    method: 'post',
                    url: '/teacher/getAllNClass',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data) {
                        this.nclassData = [];
                        for (let i = 0; i < res.data.length; i++) {
                            let nclass = {};
                            nclass.key = res.data[i].classId;
                            nclass.label = res.data[i].className;
                            this.nclassData.push(nclass);
                        }
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            //修改自然班
            handleChange(value, direction, movedKeys) {
                // console.log(value, direction, movedKeys);
                //添加
                if (direction == 'right') {
                    Axios({
                        method: 'post',
                        url: '/teacher/addNclassFromTclass',
                        data: {
                            teacherToken: localStorage.getItem("teacherToken"),
                            tClassId: this.tclassDetail[this.curClassIndex].id,
                            nClassesId: movedKeys,
                        },
                        headers: {
                            'Content-Type': 'application/json'
                        },
                    }).then((res) => {
                        // console.log(res);
                        if (res.data == 3) {
                            this.$router.push({path: "/login"})
                            return;
                        }
                        if (res.data.state == 0) {
                            this.$message.error("添加失败，请联系管理员");
                            return;
                        }
                        if (res.data.state == 1) {
                            this.$message({
                                message: '添加成功',
                                type: 'success',
                            });
                            return;
                        }
                    }).catch((err) => {
                        console.log(err);
                    })
                }
                //删除
                else if (direction == 'left') {
                    Axios({
                        method: 'post',
                        url: '/teacher/delNclassFromTclass',
                        data: {
                            teacherToken: localStorage.getItem("teacherToken"),
                            tClassId: this.tclassDetail[this.curClassIndex].id,
                            nClassesId: movedKeys,
                        },
                        headers: {
                            'Content-Type': 'application/json'
                        },
                    }).then((res) => {
                        // console.log(res);
                        if (res.data == 3) {
                            this.$router.push({path: "/login"})
                            return;
                        }
                        if (res.data.state == 0) {
                            this.$message.error("删除失败，请联系管理员");
                            return;
                        }
                        if (res.data.state == 1) {
                            this.$message({
                                message: '删除成功',
                                type: 'success',
                            });
                            return;
                        }
                    }).catch((err) => {
                        console.log(err);
                    })
                }
            },
            requestLib() {
                Axios({
                    method: 'post',
                    url: '/teacher/getProblemLib',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    // console.log(res.data)
                    this.Lib = [];
                    this.qLib = [];
                    this.questCurPage = 1;
                    for (let i = 0; i < res.data.length; i++) {
                        let Lib = {};
                        Lib.id = res.data[i].problem_id;
                        Lib.name = res.data[i].problem_name;
                        Lib.type = res.data[i].problem_category_name;
                        Lib.stem = res.data[i].problem_description;
                        Lib.source = '本校题库';
                        Lib.difficulty = res.data[i].problem_tag_name;
                        Lib.isAdded = false;

                        let detail = {};
                        detail.description = res.data[i].problem_description;
                        detail.input = res.data[i].problem_input_format;
                        detail.output = res.data[i].problem_output_format;
                        detail.inputSample = res.data[i].problem_sample_input;
                        detail.outputSample = res.data[i].problem_sample_output;
                        detail.timeLimit = res.data[i].problem_time_limit;
                        detail.memoryLimit = res.data[i].problem_memory_limit;
                        detail.hint = res.data[i].problem_hint;
                        //处理换行
                        detail.inputSample = detail.inputSample.replace(/\n/g, "<br>");
                        detail.outputSample = detail.outputSample.replace(/\n/g, "<br>");
                        detail.output = detail.output.replace(/\n/g, "<br>");
                        detail.input = detail.input.replace(/\n/g, "<br>");
                        detail.description = detail.description.replace(/\n/g, "<br>");
                        detail.outputSample = detail.outputSample.replace(new RegExp(/( )/g), "&nbsp;&nbsp;&nbsp;");
                        //处理图片
                        let temp = detail.description;
                        let picIndex = temp.indexOf('[1]:');
                        if (picIndex != -1) {
                            let picAddress = [];
                            picAddress = temp.substring(picIndex).replace('<br>', ',').replace(new RegExp(/( )/g), "").split(',');
                            for (let i = 0; i < picAddress.length; i++) {
                                picAddress[i] = "<img src='" + picAddress[i].substring(4) + "'>";
                            }
                            detail.description = detail.description.substring(0, picIndex);
                            for (let i = 0; i < picAddress.length; i++) {
                                let pic = detail.description.indexOf('![enter image description here]');
                                let head = detail.description.substring(0, pic);
                                let tail = detail.description.substring(pic + 34, detail.description.length);
                                detail.description = head + picAddress[i] + tail;
                            }
                        }
                        Lib.detail = detail;
                        this.Lib.push(Lib);
                        this.qLib.push(Lib);
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            assignHomework(index) {
                this.toAddQuestion = true;
                this.curClassIndex = index;
                this.Lib = this.qLib;
                this.categValue = '';
                this.questKeyInput = '';
            },
            addQuestion(index) {
                this.homeworkForm.name = this.Lib[index].id + ' ' + this.Lib[index].name;
                this.homeworkForm.tclass = this.tclassDetail[this.curClassIndex].name;
                this.homeworkForm.dateTime = '';
                this.homeworkForm.teacher = localStorage.getItem("teacherName");
                this.curProblemIndex = index;
                // this.toAddQuestion = false;
                this.homeworkForm.dateTime = [new Date(), new Date()]
                this.toCreateHomework = true;
            },
            // 查看题目详情
            viewProblemDetail(index) {
                this.curProblemIndex = index;
                this.problemDetail = this.Lib[index];
                this.$axios({
                    method: 'post',
                    url: '/teacher/getCurCheckpoints',
                    data: {
                        pid: this.Lib[index].id,
                        teacherToken: localStorage.getItem("teacherToken")
                    },
                    transformRequest: [
                        function (data) {
                            let ret = '';
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret;
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    // console.log(res.data);
                    this.curCheckpoints = res.data;
                    this.toViewProblemDetail = true;
                }).catch((err) => {
                    this.$notify({
                        title: '错误',
                        message: '数据获取失败',
                        type: 'error',
                        duration: 3000
                    });
                    console.log(err);
                });
                this.getProblemStandardAnswer(index)
            },

            getProblemStandardAnswer(index) {
                this.$axios({
                    method: 'post',
                    url: '/training/submission/getLatestSubmissions',
                    data: {
                        problemId: this.Lib[index].id,
                        limit: 10,
                        userName: 'administrator',
                    },
                    transformRequest: [
                        function (data) {
                            let ret = '';
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret;
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    // console.log(res.data);
                    if (res.data.content.length > 0) {
                        let submissions = res.data.content
                        for (let i = 0; i < submissions.length; i++) {
                            let submission = submissions[i]
                            if (submission.judgeScore === 100) {
                                this.standardAnswer = submission.code;
                                this.standardAnswerLanguage = submission.language.languageName
                                break;
                            }
                        }
                    } else {
                        this.standardAnswerLanguage = ''
                        this.standardAnswer = '管理员尚未发布标准答案...'
                    }
                    console.log(this.standardAnswer)
                }).catch((err) => {
                    this.$notify({
                        title: '错误',
                        message: '数据获取失败',
                        type: 'error',
                        duration: 3000
                    });
                    console.log(err);
                });
            },

            cloneHomework() {

                if (this.cloneSelectProblemList.length == 0) {
                    this.$message.warning("请选择至少一个题目");
                    return;
                }
                for (let i = 0; i < this.cloneSelectProblemList.length; i++) {
                    Axios({
                        method: 'post',
                        url: '/teacher/assignHomework',
                        data: {
                            teacherToken: localStorage.getItem("teacherToken"),
                            class_id: this.tclassDetail[this.curClassIndex].id,
                            problem_id: this.cloneSelectProblemList[i].id,
                            start_time: this.cloneSelectProblemList[i].startTimestamp,
                            end_time: this.cloneSelectProblemList[i].endTimestamp,
                            status: 0,
                            language: this.cloneSelectProblemList[i].language,
                        },
                        headers: {
                            'Content-Type': 'application/json'
                        },
                    }).then((res) => {
                        if (res.data == 3) {
                            this.$router.push({path: "/login"})
                            return;
                        }

                        if (res.data.state == 0) {
                            this.$message.error("布置作业失败！请联系管理员。");
                            return;
                        }
                        if (res.data.state == 1) {
                            this.$message.warning("题目 " + this.cloneSelectProblemList[i].id + " 已被布置到这个教学班级");
                            return;
                        }
                        if (res.data.state == 2) {
                            this.$message({
                                message: "题目 " + this.cloneSelectProblemList[i].id + "布置作业成功",
                                type: 'success',
                            });
                        }
                    }).catch((err) => {
                        console.log(err);
                    })
                }

                this.viewHomeworkByClass(this.curClassIndex);

            },


            createHomework() {
                this.$refs['homeworkForm'].validate((valid) => {
                    if (valid || !valid) {
                        let startTime = new Date(this.homeworkForm.dateTime[0]);
                        let endTime = new Date(this.homeworkForm.dateTime[1]);
                        if (endTime < startTime) {
                            this.$message.error("结束时间必须大于开始时间");
                            return;
                        }

                        Axios({
                            method: 'post',
                            url: '/teacher/assignHomework',
                            data: {
                                teacherToken: localStorage.getItem("teacherToken"),
                                class_id: this.tclassDetail[this.curClassIndex].id,
                                problem_id: this.Lib[this.curProblemIndex].id,
                                start_time: this.homeworkForm.dateTime[0].getTime(),
                                end_time: this.homeworkForm.dateTime[1].getTime(),
                                status: 0,
                                language: this.language,
                            },
                            headers: {
                                'Content-Type': 'application/json'
                            },
                        }).then((res) => {
                            if (res.data == 3) {
                                this.$router.push({path: "/login"})
                                return;
                            }

                            if (res.data.state == 0) {
                                this.$message.error("布置作业失败！请联系管理员。");
                                return;
                            }
                            if (res.data.state == 1) {
                                this.$message.error("该题目已被布置到这个教学班级");
                                return;
                            }
                            if (res.data.state == 2) {
                                this.$message({
                                    message: '布置作业成功',
                                    type: 'success',
                                });
                                this.toCreateHomework = false;
                                this.clearHomeworkForm();
                            }
                        }).catch((err) => {
                            console.log(err);
                        })
                    }
                })
            },
            viewHomeworkByClass(index) {
                this.curClassIndex = index;
                this.tclassHomeworkDetail = [];
                this.currentClassID = this.tclassDetail[index].id;
                Axios({
                    method: 'post',
                    url: '/teacher/findHomeworkBytClassId',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.tclassDetail[index].id,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    // console.log(res.data)
                    if (res.data) {
                        for (let i = 0; i < res.data.length; i++) {
                            let homeworkDetail = {};
                            homeworkDetail.id = res.data[i].problem_id;
                            homeworkDetail.name = res.data[i].problem_name;
                            homeworkDetail.description = res.data[i].problem_description;
                            homeworkDetail.type = res.data[i].problem_category_name;
                            homeworkDetail.status = res.data[i].status;
                            homeworkDetail.endTime = this.getTime(res.data[i].end_time);
                            homeworkDetail.endTimestamp = res.data[i].end_time;
                            homeworkDetail.startTime = this.getTime(res.data[i].start_time);
                            homeworkDetail.startTimestamp = res.data[i].start_time;
                            homeworkDetail.language = res.data[i].language;
                            this.tclassHomeworkDetail.push(homeworkDetail);
                        }
                    }

                }).catch((err) => {
                    console.log(err);
                })
                this.toViewHomeworkByClass = true;
            },

            findHomeworkByCloneClassId() {
                this.cloneSourceProblem = []
                Axios({
                    method: 'post',
                    url: '/teacher/findHomeworkBytClassId',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.cloneClassId,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    // console.log(res.data)
                    if (res.data) {
                        for (let i = 0; i < res.data.length; i++) {
                            let homeworkDetail = {};
                            homeworkDetail.id = res.data[i].problem_id;
                            homeworkDetail.name = res.data[i].problem_name;
                            homeworkDetail.description = res.data[i].problem_description;
                            homeworkDetail.type = res.data[i].problem_category_name;
                            homeworkDetail.status = res.data[i].status;
                            homeworkDetail.endTime = this.getTime(res.data[i].end_time);
                            homeworkDetail.endTimestamp = res.data[i].end_time;
                            homeworkDetail.startTime = this.getTime(res.data[i].start_time);
                            homeworkDetail.startTimestamp = res.data[i].start_time;
                            homeworkDetail.language = res.data[i].language;
                            this.cloneSourceProblem.push(homeworkDetail);
                        }
                    }
                    this.oldCloneSourceProblem = this.deepCopy(this.cloneSourceProblem)

                }).catch((err) => {
                    console.log(err);
                })
            },

            deepCopy(obj) {
                if (typeof obj !== 'object' || obj === null) {
                    // 如果不是引用类型或者是 null，直接返回
                    return obj;
                }

                let newObj = Array.isArray(obj) ? [] : {};
                for (let key in obj) {
                    if (Object.prototype.hasOwnProperty.call(obj, key)) {
                        newObj[key] = this.deepCopy(obj[key]);
                    }
                }
                return newObj;
            },

            modifyCloneHomeworkTime() {
                if (isNaN(this.addCloneDays) || this.addCloneDays === '') {
                    this.$message.warning("请输入数字...")
                    return;
                }
                if (this.cloneSourceProblem.length === 0) {
                    this.$message.warning('请选择需要克隆的作业...')
                    return;
                }
                for (let i = 0; i < this.cloneSourceProblem.length; i++) {
                    this.cloneSourceProblem[i].startTimestamp = this.oldCloneSourceProblem[i].startTimestamp + (this.addCloneDays * 24 * 60 * 60 * 1000);
                    this.cloneSourceProblem[i].endTimestamp = this.oldCloneSourceProblem[i].endTimestamp + (this.addCloneDays * 24 * 60 * 60 * 1000);
                    this.cloneSourceProblem[i].startTime = this.getTime(this.cloneSourceProblem[i].startTimestamp);
                    this.cloneSourceProblem[i].endTime = this.getTime(this.cloneSourceProblem[i].endTimestamp);
                }
                this.$message.success("请核对克隆作业时间的变化...")
            },

            viewStudentByHomework(index) {
                // console.log(this.tclassHomeworkDetail[index].id);
                this.homeworkTitle = this.tclassHomeworkDetail[index].name;
                this.curHomeworkIndex = index;
                this.stuCurPage = 1;
                Axios({
                    method: 'post',
                    url: '/teacher/findHomeworkDetailByIds',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.tclassDetail[this.curClassIndex].id,
                        problem_id: this.tclassHomeworkDetail[index].id,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log('================')
                    // console.log(res.data);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data) {
                        this.studentDetail = [];
                        for (let i = 0; i < res.data.length; i++) {
                            let student = {};
                            student.id = res.data[i].stu_id;
                            student.name = res.data[i].stu_name;
                            student.submitCount = res.data[i].submit_count;
                            student.grade = res.data[i].score;
                            student.submitTime = res.data[i].submit_time == 0 ? null : this.getTime(res.data[i].submit_time);
                            student.status = res.data[i].status;
                            student.answer = res.data[i].answer;
                            // if (res.data[i].answer != null)
                            //     student.answer = res.data[i].answer.replace(/\n/g, "<br>").replace(/\s/g, "&nbsp;");
                            student.problemDescription = res.data[i].problem_description;
                            student.language = res.data[i].language;
                            this.studentDetail.push(student);
                        }
                        this.hwStudents = this.studentDetail;
                    }
                    this.toViewHomeworkDetail = true;
                }).catch((err) => {
                    console.log(err);
                })
            },
            //下载该教学班的所有作业成绩
            downloadExcel(index) {
                console.log("downloadExcel");
                let selectedProblemIdList = [];
                let downloadUrl = process.env.VUE_APP_URL + "/teacher/downloadScoreToExcelById?teacherId="
                    + localStorage.getItem("teacherId")
                    + "&class_id=" + this.tclassDetail[index].id +
                    "&teacherToken=" + localStorage.getItem("teacherToken")
                    + "&selectedProblemIdList=" + selectedProblemIdList;
                let a = document.createElement("a");
                a.href = downloadUrl;
                a.download = downloadUrl;
                a.click();
                return false;
            },

            viewCloneHomeworkPage() {

            },

            searchCloneHomeworkProblem() {
                this.findHomeworkByCloneClassId();
            },

            downloadExcelBySelectedProblemId() {
                if (this.selectedProblemList.length == 0) {
                    this.$message.warning("请选择至少一个题目导出学生成绩");
                    return;
                }
                let selectedProblemIdList = [];
                for (let i = 0; i < this.selectedProblemList.length; i++) {
                    selectedProblemIdList.push(this.selectedProblemList[i].id);
                }
                console.log("downloadExcel");
                let downloadUrl = process.env.VUE_APP_URL + "/teacher/downloadScoreToExcelById?" +
                    "teacherId=" + localStorage.getItem("teacherId")
                    + "&class_id=" + this.currentClassID +
                    "&teacherToken=" + localStorage.getItem("teacherToken")
                    + "&selectedProblemIdList=" + selectedProblemIdList;
                let a = document.createElement("a");
                a.href = downloadUrl;
                a.download = downloadUrl;
                a.click();
                return false;
            },
            //查重报告，下载重复率检测报告
            downloadRepCheckReport() {
                let downloadUrl = process.env.VUE_APP_URL
                    + "/teacher/downloadRepCheckReport?teacherId=" + localStorage.getItem("teacherId")
                    + "&classId=" + this.tclassDetail[this.curClassIndex].id
                    + "&className=" + this.tclassDetail[this.curClassIndex].name
                    + "&problemId=" + this.tclassHomeworkDetail[this.curHomeworkIndex].id
                    + "&problemName=" + this.tclassHomeworkDetail[this.curHomeworkIndex].name
                    + "&teacherToken=" + localStorage.getItem("teacherToken");
                let a = document.createElement("a");
                a.href = downloadUrl;
                a.download = downloadUrl;
                a.click();
                return false;
            },
            //查阅学生答案
            reviewStuPaper(index) {
                this.curStuIndex = index;
                this.toReviewStuPaper = true;
            },
            //修改学生成绩
            uploadScore() {
                Axios({
                    method: 'post',
                    url: '/teacher/modifyStudentScoreByIds',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.tclassDetail[this.curClassIndex].id,
                        problem_id: this.tclassHomeworkDetail[this.curHomeworkIndex].id,
                        stu_id: this.studentDetail[this.curStuIndex].id,
                        score: this.studentDetail[this.curStuIndex].grade,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log(res);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data.state == 0) {
                        this.$message.error("修改失败");
                        return;
                    }
                    if (res.data.state == 1) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                        })
                        this.toReviewStuPaper = false;
                        return;
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            //结束作业
            endHomework(index) {
                // console.log(index);
                Axios({
                    method: 'post',
                    url: '/teacher/endHomeworkByIds',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.tclassDetail[this.curClassIndex].id,
                        problem_id: this.tclassHomeworkDetail[index].id,
                        status: 1,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log(res);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }

                    if (res.data.state == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                        })
                        this.tclassHomeworkDetail[index].status = 1;
                        this.toEndHomework = false;
                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            //修改作业时间
            changeHomeworkTime(index) {
                this.clearHomeworkForm();
                this.curHomeworkIndex = index;
                this.toChangeHomeworkTime = true;
                this.homeworkForm.teacher = localStorage.getItem("teacherName");
                this.homeworkForm.dateTime = [this.tclassHomeworkDetail[index].startTimestamp,
                    this.tclassHomeworkDetail[index].endTimestamp];
                this.homeworkForm.tclass = this.tclassDetail[this.curClassIndex].name;
                this.homeworkForm.name = this.tclassHomeworkDetail[index].name;
                this.language = this.tclassHomeworkDetail[index].language;
            },
            changeHomeworkTimeComfirm() {

                this.$refs['homeworkForm'].validate((valid) => {
                    if (valid || !valid) {
                        let startTime = new Date(this.homeworkForm.dateTime[0]);
                        let endTime = new Date(this.homeworkForm.dateTime[1]);
                        if (endTime < startTime) {
                            this.$message.error("结束时间必须大于开始时间");
                            return;
                        }

                        Axios({
                            method: 'post',
                            url: '/teacher/modifyHEndTimeByIds',
                            data: {
                                teacherToken: localStorage.getItem("teacherToken"),
                                class_id: this.tclassDetail[this.curClassIndex].id,
                                problem_id: this.tclassHomeworkDetail[this.curHomeworkIndex].id,
                                start_time: startTime.getTime(),
                                end_time: endTime.getTime(),
                                status: this.tclassHomeworkDetail[this.curHomeworkIndex].status,
                                language: this.language
                            },
                            transformRequest: [
                                function (data) {
                                    let ret = ''
                                    for (let it in data) {
                                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                                    }
                                    ret = ret.substring(0, ret.lastIndexOf('&'));
                                    return ret
                                }
                            ],
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            },
                        }).then((res) => {
                            // console.log(res);
                            if (res.data == 3) {
                                this.$router.push({path: "/login"})
                                return;
                            }

                            if (res.data.state == 1) {
                                this.$message({
                                    message: '修改成功',
                                    type: 'success',
                                })
                                this.toChangeHomeworkTime = false;
                                this.viewHomeworkByClass(this.curClassIndex);
                                return;
                            }
                            if (res.data.state == 0) {
                                this.$message.error("修改失败");
                                return;
                            }
                        }).catch((err) => {
                            console.log(err);
                        })

                    }
                })

            },
            requestProblemType() {
                Axios({
                    method: 'post',
                    url: '/teacher/getProblemType',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log(res);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    if (res.data) {
                        this.categOptions = [];
                        for (let i = res.data.length - 1; i >= 0; i--) {
                            let map = {};
                            map.value = i;
                            map.label = res.data[i];
                            this.categOptions.push(map);
                        }
                    }

                }).catch((err) => {
                    console.log(err);
                })
            },
            //根据分类搜索题目
            problemTypeSearch() {
                this.Lib = [];
                this.questCurPage = 1;
                for (let i = 0; i < this.qLib.length; i++) {
                    if (this.qLib[i].type.indexOf(this.categValue) >= 0) {
                        this.Lib.push(this.qLib[i]);
                    }
                }
            },
            //根据题目名称、类型或难度的关键词搜索题目
            searchProblemsByKey() {
                if (this.questKeyInput.length > 0) {
                    this.Lib = [];
                    this.questCurPage = 1;
                    for (let i = 0; i < this.qLib.length; i++) {
                        if (this.qLib[i].name.toLowerCase().indexOf(this.questKeyInput.toLowerCase()) >= 0
                            || this.qLib[i].type.indexOf(this.questKeyInput) >= 0
                            || this.qLib[i].difficulty.indexOf(this.questKeyInput) >= 0) {
                            this.Lib.push(this.qLib[i]);
                        }
                    }
                } else
                    this.$message.warning("请先输入关键词！");
            },
            //刷新题库
            refreshQuestLib() {
                this.questCurPage = 1;
                this.Lib = this.qLib;
                this.categValue = '';
                this.questKeyInput = '';
            },
            deleteHomework(index) {
                Axios({
                    method: 'post',
                    url: '/teacher/delHomeworkByIds',
                    data: {
                        teacherToken: localStorage.getItem("teacherToken"),
                        class_id: this.tclassDetail[this.curClassIndex].id,
                        problem_id: this.tclassHomeworkDetail[this.curHomeworkIndex].id,
                    },
                    transformRequest: [
                        function (data) {
                            let ret = ''
                            for (let it in data) {
                                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                            }
                            ret = ret.substring(0, ret.lastIndexOf('&'));
                            return ret
                        }
                    ],
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    // console.log(res);
                    if (res.data == 3) {
                        this.$router.push({path: "/login"})
                        return;
                    }
                    if (res.data.state == 2) {
                        this.$message.error("已经有同学提交作业，不能删除该作业，只能结束作业");
                    }
                    if (res.data.state == 1) {
                        this.$message({
                            message: '删除成功',
                            type: 'success',
                        })
                    }
                    if (res.data.state == 0) {
                        this.$message.error('删除失败，请联系管理员');
                    }
                    this.toDeleteHomework = false;
                    this.viewHomeworkByClass(this.curClassIndex);
                }).catch((err) => {
                    console.log(err);
                })
            }
        },

        getLanguageAndEvaluation() {
            let that = this;
            this.$axios({
                method: 'post',
                url: '/user/getLanguageAndEvaluation',
                data: {
                    exam_id: this.exam.id,
                    userToken: localStorage.getItem("userToken")
                },
                transformRequest: [
                    function (data) {
                        let ret = '';
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        ret = ret.substring(0, ret.lastIndexOf('&'));
                        return ret;
                    }
                ],
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
            }).then((res) => {
                if (res.data == 3) {
                    this.$router.push({path: "/login"})
                    return;
                }
                this.languageSelect = res.data['language_select'];
                if (this.languageSelect == 1) {
                    this.languages = [{value: 'C'}]
                } else if (this.languageSelect == 2) {
                    this.languages = [{value: 'C++'}]
                }
                this.evaluationSelect = res.data['evaluation_select']
            }).catch((err) => {
                this.$notify({
                    title: '错误',
                    message: '内部出现错误',
                    type: 'error',
                    duration: 3000
                });
                console.log(err);
            });
        },

    }
</script>

<style scoped>
    .exam {
        width: 100%;
    }

    .filter-container {
        padding-bottom: 10px;
    }

    .filter-item {
        display: inline-block;
        vertical-align: middle;
        margin-bottom: 10px;
    }

    .item-input {
        width: 200px;
        margin-right: 5px;
    }

    .filter-container .filter-item:nth-child(3), .filter-container .filter-item:nth-child(4) {
        margin-left: 16px;
    }

    .exam-list {
        width: 100%;
    }

    .pagination-container {
        margin-top: 30px;
    }

    .exam-list .col2-cell-style {
        color: #409EFF;
        cursor: pointer;
    }

    .filter-bar {
        width: 100%;
        padding-bottom: 10px;
    }

    .filter-bar .el-input {
        width: 200px;
        margin-right: 5px;
    }

    .filter-bar .item-margin-left-16 {
        margin-left: 16px;
    }

    .el-dialog .el-table .col2-cell-style {
        color: #409EFF;
        cursor: pointer;
    }

    .el-dialog .stu-paper-container {
        margin: 0 20px;
    }

    .el-dialog .stu-paper-container h1 {
        text-align: center;
        font-size: 2.5em;
    }

    .el-dialog .stu-paper-container h3 {
        text-align: left;
    }

    .el-dialog .stu-paper-container .el-row {
        margin-bottom: 30px;
    }

    .el-dialog .stu-paper-container .stu-answer {
        margin-left: 20px;
    }

    .el-dialog .stu-paper-container .stu-paper-footer {
        text-align: right;
        margin-top: 30px;
    }

    .el-dialog .paper-container {
        margin: 0 20px;
    }

    .el-dialog .paper-container .paper-header h1 {
        text-align: center;
        font-size: 2.5em;
    }

    .el-dialog .paper-container .paper-info {
        text-align: center;
        padding: 20px;
    }

    .el-dialog .paper-container .paper-info h3 {
        display: inline-block;
        width: 25%;
    }

    .paper-container .paper-content {
        padding: 20px;
    }

    .take-up-header {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .take-up-header .header-icon {
        display: flex;
        color: #f8bb86;
        position: relative;
        justify-content: center;
        width: 5em;
        height: 5em;
        margin: 0 auto 1.875em;
        border: .25em #facea8 solid;
        border-radius: 50%;
        line-height: 5em;
        box-sizing: content-box;
    }

    .take-up-header .header-icon .icon-text {
        font-size: 3.75em;
    }

    .take-up-header .header-title {
        display: block;
        position: relative;
        max-width: 100%;
        margin: 0 0 0.4em;
        padding: 0;
        color: #595959;
        font-size: 2em;
        font-weight: 600;
        text-align: center;
        text-transform: none;
        word-wrap: break-word;
    }

    .take-up-content {
        color: #545454;
        font-size: 1.25em;
        font-weight: 300;
        text-align: center;
    }

    .transfeLayout {
        margin-left: 120px;
        margin-bottom: 25px;
    }

    .transfeTitle {
        width: 120px;
        height: 0px;
        padding-left: 12px;
        margin-bottom: 0px;
    }

    .problem-detail .problem-header {
        background-color: #16a085;
        color: #fff;
        padding: 10px;
    }

    .problem-body {
        padding: 20px;
        background-color: white;
    }

    .problem-body .border-top-style, .checkpoints {
        border-top: 5px solid #16a085;
        padding-top: 10px;
        margin-top: 30px;
    }

    .problem-body .border-top-style .description .first-checkpoint {
        border-top-width: 0;
        padding-top: 0;
        margin-top: 0;
    }

    .problem-body .sample {
        border-top-color: #ff7373;
    }

    .problem-body .description, .checkpoints-body .description {
        color: #666;
        margin-left: 20px;
    }

    .problem-detail h4 {
        font-size: 18px;
        margin-top: 4px;
    }

    .problem-detail h5 {
        font-size: 17px;
    }

    .problem-detail h6 {
        font-size: 16px;
    }

    .problem-detail h4, .problem-detail h5, .problem-detail h6 {
        font-weight: 500;
        margin: 10px 0;
        text-transform: uppercase;
    }

    .problem-detail p {
        margin-bottom: 10px;
    }

    .problem-detail .sample pre {
        display: block;
        padding: 10px;
        margin: 0 0 10px;
        font-size: 13px;
        line-height: 20px;
        word-break: break-all;
        word-wrap: break-word;
        white-space: pre-wrap;
        background-color: #f5f5f5;
        border: 1px solid rgba(0, 0, 0, 0.15);
        border-radius: 4px;
    }



    .p-operation {
        background-color: white;
        padding: 10px;
        border-top: 4px solid #16a085;
    }

    .p-operation .op-list {
        font-size: 14px;
        line-height: 2;
    }

    .code {
        border: 1px solid lightseagreen;
    }

    .op-list ul {
        list-style: none;
        padding-left: 0;
    }

    .op-list ul .op-li {
        color: #16a085;
        cursor: pointer;
    }

    .op-list ul .li-score {
        font-size: 16px;
        font-weight: bold;
        font-style: italic;
    }


</style>